/*
* Copyright 2023 NXP
* NXP Confidential and Proprietary. This software is owned or controlled by NXP and may only be used strictly in
* accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
* activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms.  If you do not agree to be bound by the applicable license
* terms, then you may not retain, install, activate or otherwise use the software.
*/

#include "events_init.h"
#include <stdio.h>
#include "lvgl.h"


static int avg_speed=0;
static int trip_flag=0;
int trip_ride_flag = 0;
/* 定时器回调函数 */
void timer_callback(lv_timer_t *timer)
{
  /* 恢复文本框的原本颜色 */
  lv_obj_set_style_border_color(guider_ui.Trip_frame, lv_color_hex(0x000000), LV_PART_MAIN|LV_STATE_DEFAULT);
  /* 删除定时器 */
  lv_timer_del(timer);
}
static void Trip_digital_clock_1_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_VALUE_CHANGED:
	{
		
		break;
	}
	default:
		break;
	}
}
static void Trip_speed_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		
		break;
	}
	default:
		break;
	}
}
static void Trip_avg_speed_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		
		break;
	}
	default:
		break;
	}
}
static void Trip_back_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		//Write the load screen code.
	    lv_obj_t * act_scr = lv_scr_act();
	    lv_disp_t * d = lv_obj_get_disp(act_scr);
	    if (d->prev_scr == NULL && (d->scr_to_load == NULL || d->scr_to_load == act_scr)) {
	        if (guider_ui.table_del == true) {
	          setup_scr_table(&guider_ui);
	        }
	        lv_scr_load_anim(guider_ui.table, LV_SCR_LOAD_ANIM_FADE_ON, 10, 0, true);
	        guider_ui.table_del = true;
	    }
		break;
	}
	default:
		break;
	}
}
static void Trip_start_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		if(trip_flag==0)
	{
	  lv_label_set_text(guider_ui.Trip_start_label, "End");
	  lv_obj_set_style_text_color(guider_ui.Trip_start, lv_color_hex(0xF00000), LV_PART_MAIN|LV_STATE_DEFAULT);
	  lv_obj_set_style_border_color(guider_ui.Trip_frame, lv_color_hex(0x2FDA64), LV_PART_MAIN|LV_STATE_DEFAULT);
	  /* 创建并启动定时器，2000ms后执行回调函数 */
	    lv_timer_create(timer_callback, 1300, NULL);
	  trip_flag=1;
	  trip_ride_flag = 1;
	}
	else
	{
	  lv_label_set_text(guider_ui.Trip_start_label, "Start");
	  lv_obj_set_style_text_color(guider_ui.Trip_start, lv_color_hex(0x2FDA64), LV_PART_MAIN|LV_STATE_DEFAULT);
	  lv_obj_set_style_border_color(guider_ui.Trip_frame, lv_color_hex(0xF00000), LV_PART_MAIN|LV_STATE_DEFAULT);
	  /* 创建并启动定时器，2000ms后执行回调函数 */
	  lv_timer_create(timer_callback, 1300, NULL);
	  trip_flag=0;
	  trip_ride_flag = 0;
	}
	
	
	
	
	
		break;
	}
	default:
		break;
	}
}
void events_init_Trip(lv_ui *ui)
{
	lv_obj_add_event_cb(ui->Trip_digital_clock_1, Trip_digital_clock_1_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_add_event_cb(ui->Trip_speed, Trip_speed_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_add_event_cb(ui->Trip_avg_speed, Trip_avg_speed_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_add_event_cb(ui->Trip_back, Trip_back_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_add_event_cb(ui->Trip_start, Trip_start_event_handler, LV_EVENT_ALL, NULL);
}
static void table_setting_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		//Write the load screen code.
	    lv_obj_t * act_scr = lv_scr_act();
	    lv_disp_t * d = lv_obj_get_disp(act_scr);
	    if (d->prev_scr == NULL && (d->scr_to_load == NULL || d->scr_to_load == act_scr)) {
	        if (guider_ui.setting_del == true) {
	        //   setup_scr_setting(&guider_ui);
				setup_scr_WIFI(&guider_ui);
	        }
	        // lv_scr_load_anim(guider_ui.setting, LV_SCR_LOAD_ANIM_FADE_ON, 300, 0, true);
			lv_scr_load_anim(guider_ui.WIFI, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, true);
	        guider_ui.setting_del = true;
	    }
		break;
	}
	default:
		break;
	}
}
static void table_start_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		//Write the load screen code.
	    lv_obj_t * act_scr = lv_scr_act();
	    lv_disp_t * d = lv_obj_get_disp(act_scr);
	    if (d->prev_scr == NULL && (d->scr_to_load == NULL || d->scr_to_load == act_scr)) {
	        if (guider_ui.Trip_del == true) {
	          setup_scr_Trip(&guider_ui);
	        }
	        lv_scr_load_anim(guider_ui.Trip, LV_SCR_LOAD_ANIM_FADE_ON, 10, 0, true);
	        guider_ui.Trip_del = true;
	    }
		break;
	}
	default:
		break;
	}
}
void events_init_table(lv_ui *ui)
{
	lv_obj_add_event_cb(ui->table_setting, table_setting_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_add_event_cb(ui->table_start, table_start_event_handler, LV_EVENT_ALL, NULL);
}
static void setting_list_1_item2_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		//Write the load screen code.
	    lv_obj_t * act_scr = lv_scr_act();
	    lv_disp_t * d = lv_obj_get_disp(act_scr);
	    if (d->prev_scr == NULL && (d->scr_to_load == NULL || d->scr_to_load == act_scr)) {
	        if (guider_ui.WIFI_del == true) {
	          setup_scr_WIFI(&guider_ui);
	        }
	        lv_scr_load_anim(guider_ui.WIFI, LV_SCR_LOAD_ANIM_MOVE_LEFT, 200, 0, true);
	        guider_ui.WIFI_del = true;
	    }
		break;
	}
	default:
		break;
	}
}
static void setting_list_1_item5_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		//Write the load screen code.
	    lv_obj_t * act_scr = lv_scr_act();
	    lv_disp_t * d = lv_obj_get_disp(act_scr);
	    if (d->prev_scr == NULL && (d->scr_to_load == NULL || d->scr_to_load == act_scr)) {
	        if (guider_ui.table_del == true) {
	          setup_scr_table(&guider_ui);
	        }
	        lv_scr_load_anim(guider_ui.table, LV_SCR_LOAD_ANIM_FADE_ON, 300, 0, true);
	        guider_ui.table_del = true;
	    }
		break;
	}
	default:
		break;
	}
}
void events_init_setting(lv_ui *ui)
{
	lv_obj_add_event_cb(ui->setting_list_1_item2, setting_list_1_item2_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_add_event_cb(ui->setting_list_1_item5, setting_list_1_item5_event_handler, LV_EVENT_ALL, NULL);
}
static void WIFI_btn_1_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);

	switch (code) {
	case LV_EVENT_CLICKED:
	{
		//Write the load screen code.
	    lv_obj_t * act_scr = lv_scr_act();
	    lv_disp_t * d = lv_obj_get_disp(act_scr);
	    if (d->prev_scr == NULL && (d->scr_to_load == NULL || d->scr_to_load == act_scr)) {
	        if (guider_ui.setting_del == true) {
	        //   setup_scr_setting(&guider_ui);
				setup_scr_table(&guider_ui);
	        }
	        // lv_scr_load_anim(guider_ui.setting, LV_SCR_LOAD_ANIM_MOVE_RIGHT, 300, 0, true);
			lv_scr_load_anim(guider_ui.table, LV_SCR_LOAD_ANIM_MOVE_RIGHT, 10, 0, true);
	        guider_ui.setting_del = true;
	    }
		break;
	}
	default:
		break;
	}
}
void events_init_WIFI(lv_ui *ui)
{
	lv_obj_add_event_cb(ui->WIFI_btn_1, WIFI_btn_1_event_handler, LV_EVENT_ALL, NULL);
}

void events_init(lv_ui *ui)
{

}
